package xyz.thoughtset.viewer.common.exc.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import xyz.thoughtset.viewer.common.core.entity.IdMeta;
import xyz.thoughtset.viewer.common.crud.core.annotation.ApiCRUDPower;
import xyz.thoughtset.viewer.common.exc.exceptions.ExecException;

import java.util.Map;

@NoArgsConstructor
@AllArgsConstructor
@Data
@TableName
@ApiCRUDPower(searchOnly = true,list = true)
public class ExcInfo extends IdMeta {
    protected String funId;
    protected String errType;
    protected String errMsg;
    protected String apiId;
    protected String blockId;
    protected String paramStr;
    protected transient Map params;

    public ExcInfo(Exception exc){
        this.errType = exc.getClass().getName();
        this.errMsg = exc.getMessage();
    }

    public static ExecException buildAndThrowExc(Exception exc, Map params){
        ExcInfo e = new ExcInfo(exc);
        e.setParams(params);
        return new ExecException(e);
    }

}
